<?php
class Gongwen_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($_POST['type'])?$_POST['type']:false;
		$type=!empty($xxfget['type'])?$xxfget['type']:$type;
        if(!$type){
            $result=xdb::getInstance()->getarray("select * from news where ntype like 'gongwen' and uid=".XXF_UID." order by id desc");
        	$this::show('gongwenmanage',compact('result'));
        }else{
            $this::$type();
        }
    }
    function add(){
        $user=xdb::getInstance()->getarray("select id,realname from `user` where status='1' and zhiwu not in ('外聘','测试实习','值班室','学员公寓前台')");
        $this->show("gongwenadd",compact('user'));
    }
    function addaction(){
        $uid=XXF_UID;
        $ntitle=$_POST['ntitle'];
        $content=$_POST['content'];
        $ids=$_POST['ids'];
        $array=array();
        $array['uid']=$uid;
        $array['ntitle']=$ntitle;
        $array['ncontent']=$content;
        $array['ntype']="gongwen";
        $array2=array();
        $array2['id']=0;
        xdb::getInstance()->indb("news", $array, $array2);
        $nid=xdb::getInstance()->getvar("select max(id) from news");
        if($ids!="id"){
            $ids=explode("_", $ids);
            for($i=1;$i<count($ids);$i++){
                xdb::getInstance()->indb("user_gongwen_news", array('uid'=>$ids[$i],'nid'=>$nid), array('id'=>0));
            }
        }
        echo 1;
    }
}